/**
 * @param {Flickr.PhotoSummary} api
 * @param {Enum.size} sizeID
 * @constructor
 */
function Size(api, sizeID)
{
	"use strict";

	/** @type {Size} */
	var _size = this;
	this.id = sizeID;
	this.width = 0;
	this.height = 0;
	this.url = api[sizeID];     // reference property as collection member

	function init()
	{
		if (_size.url)
		{
			_size.width =  parseInt(api[sizeID.replace('url', 'width')]);
			_size.height = parseInt(api[sizeID.replace('url', 'height')]);
		}
	}

	/**
	 * Whether URL and dimensions have values
	 * @return {Boolean}
	 */
	this.valid = function()
	{
		return (!Format.isEmpty(_size.url) && _size.width > 0 && _size.height > 0);
	};

	/**
	 * Whether the size fits within constraints
	 * @param {Number} maxWidth
	 * @param {Number} maxHeight
	 * @param {Number} maxWidthForAnyHeight Width below which any height is allowed
	 * @return {Boolean}
	 */
	this.fits = function(maxWidth, maxHeight, maxWidthForAnyHeight)
	{
		return (
			this.valid() &&
				this.width <= maxWidth &&
			   (this.height <= maxHeight || this.width < maxWidthForAnyHeight));
	};

	/**
	 * Whether the size is bigger than the given size
	 * @param {Size} other
	 * @return {Boolean}
	 */
	this.biggerThan = function(other)
	{
		return (((_size.width - other.width) + (_size.height - other.height)) > 0);
	};

	init();
}